<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<h4>Key store</h4>
<div class="form" [formGroup]="internalFormGroup">
  <mat-form-field class="field type">
    <mat-label>Type</mat-label>
    <mat-select formControlName="type">
      <mat-option *ngFor="let type of types" [value]="type.value">{{ type.label }}</mat-option>
    </mat-select>
  </mat-form-field>

  <div class="form__typeSubForm" [ngSwitch]="internalFormGroup.get('type').value">
    <ng-container *ngSwitchCase="'JKS'">
      <mat-form-field class="field">
        <mat-label>Password</mat-label>
        <input matInput formControlName="jksPassword" type="password" name="jksPassword" autocomplete="off" required />
        <mat-hint>Key store password</mat-hint>
        <mat-error *ngIf="internalFormGroup.get('jksPassword').hasError('required')"> Password is required </mat-error>
      </mat-form-field>

      <div class="pathOrContent">
        <mat-form-field class="field">
          <mat-label>Path</mat-label>
          <input matInput formControlName="jksPath" name="jksPath" autocomplete="off" />
          <mat-hint>Path to the trust store file</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('jksPath').hasError('pathOrContentRequired')"> Path or content is required </mat-error>
        </mat-form-field>

        <span class="pathOrContent__or">or</span>

        <mat-form-field class="field">
          <mat-label>Content</mat-label>
          <textarea matInput formControlName="jksContent" rows="1" name="jksContent"></textarea>
          <mat-hint>Binary content as Base64</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('jksContent').hasError('pathOrContentRequired')"> Path or content is required </mat-error>
        </mat-form-field>
      </div>
    </ng-container>

    <ng-container *ngSwitchCase="'PKCS12'">
      <mat-form-field class="field">
        <mat-label>Password</mat-label>
        <input matInput formControlName="pkcs12Password" type="password" name="pkcs12Password" autocomplete="off" required />
        <mat-hint>Key store password</mat-hint>
        <mat-error *ngIf="internalFormGroup.get('pkcs12Password').hasError('required')"> Password is required </mat-error>
      </mat-form-field>

      <div class="pathOrContent">
        <mat-form-field class="field">
          <mat-label>Path</mat-label>
          <input matInput formControlName="pkcs12Path" name="pkcs12Path" autocomplete="off" />
          <mat-hint>Path to the trust store file</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pkcs12Path').hasError('pathOrContentRequired')"> Path or content is required </mat-error>
        </mat-form-field>

        <span class="pathOrContent__or">or</span>

        <mat-form-field class="field">
          <mat-label>Content</mat-label>
          <textarea matInput formControlName="pkcs12Content" rows="1" name="pkcs12Content"></textarea>
          <mat-hint>Binary content as Base64</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pkcs12Content').hasError('pathOrContentRequired')">
            Path or content is required
          </mat-error>
        </mat-form-field>
      </div>
    </ng-container>

    <ng-container *ngSwitchCase="'PEM'">
      <div class="pathOrContent">
        <mat-form-field class="field">
          <mat-label>Key path</mat-label>
          <input matInput formControlName="pemKeyPath" name="pemKeyPath" autocomplete="off" />
          <mat-hint>The key path of the key store</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pemKeyPath').hasError('pathOrContentRequired')"
            >Key path or Key content is required
          </mat-error>
        </mat-form-field>

        <span class="pathOrContent__or">or</span>

        <mat-form-field class="field">
          <mat-label>Key content</mat-label>
          <textarea matInput formControlName="pemKeyContent" rows="1" name="pemKeyContent"></textarea>
          <mat-hint>Binary key content as Base64</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pemKeyContent').hasError('pathOrContentRequired')">
            Key path or key content is required
          </mat-error>
        </mat-form-field>
      </div>

      <div class="pathOrContent">
        <mat-form-field class="field">
          <mat-label>Cert path</mat-label>
          <input matInput formControlName="pemCertPath" name="pemCertPath" autocomplete="off" />
          <mat-hint>The cert path of the key store</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pemCertPath').hasError('pathOrContentRequired')">
            Cert path or cert content is required
          </mat-error>
        </mat-form-field>

        <span class="pathOrContent__or">or</span>

        <mat-form-field class="field">
          <mat-label>Cert content</mat-label>
          <textarea matInput formControlName="pemCertContent" rows="1" name="pemCertContent"></textarea>
          <mat-hint>Binary cert content as Base64</mat-hint>
          <mat-error *ngIf="internalFormGroup.get('pemCertContent').hasError('pathOrContentRequired')">
            Cert path or cert content is required
          </mat-error>
        </mat-form-field>
      </div>
    </ng-container>
  </div>
</div>
